#ifndef _SERVICE_H
#define _SERVICE_H
#include "mypkg.h"
#include "dao.h"

//10秒内有心跳视为在线，否则掉线
#define ONLINE_SECOND 10

typedef struct{
	char loginname[20];
	char addr[30];
	int  port;
	long hearttime;//最近的一次收到心跳的时间(单位s)
}ol_data_t;

typedef struct ol{
	union{
		ol_data_t data;//用户登录信息
		int len;
	};
	struct ol* next;
}ol_link_t, ol_node_t;

//service.c
void service_init();
void service_sendMsg(char* destname, char* buf, int len);
//链表，存储在线用户信息
ol_link_t* ol_link_create();
void ol_link_destroy();
void ol_link_insert(char* name, char* addr, int port, long hearttime);
ol_data_t* ol_link_findByName(char* name); 
void ol_link_updateByName(char* name, char* addr, int port, long hearttime);
void ol_link_removeByName(char* name); 
void ol_link_show();

//service.c END

//user_service.c
int user_service_reg(char* username,char* passwd, char* sendbuf,int* buflen);
int user_service_login(char* username,char* passwd, char* ip,int port, char* sendbuf, int* sendbuLen);
int user_service_heart(char* username, char* ip, int port, char* sendbuf,int* buflen);
int user_service_logout(char* username, char* sendbuf, int* buflen);

//friend_service.c
int friend_service_list(char* username, char* sendbuf,int* sendbufLen);
int friend_service_add(char* username,char* friendname, char* sendbuf,int* sendbufLen);
int friend_service_delete(char* username,char* friendname, char* sendbuf,int* sendbufLen);
int friend_service_chat(char* username,char* friendname, char* msg, int msglen,char* sendbuf,int* sendbufLen);

//ssh_service.c
int ssh_service_ssh(char* cmd, char* sendbuf, int* bufLen);
int ssh_service_upload_start(char* username, char* dest,char* sendbuf, int* bufLen);
int ssh_service_upload_content(char* username, char* dest,char* cont,int contLen,char* sendbuf, int* bufLen);
int ssh_service_upload_end(char* username, char* dest,char* sendbuf, int* bufLen);
int ssh_service_download_start(char* username,char* serverfile, char* sendbuf, int* bufLen);
int ssh_service_download_content(char* username,char* serverfile, long start, char* sendbuf, int* bufLen);
int ssh_service_download_end(char* username,char* serverfile, char* sendbuf, int* bufLen);

//group_service.c
int group_service_mygrp(char* username, char* sendbuf, int* bufLen);
int group_service_mem(char* groupname, char* sendbuf, int* bufLen);
int group_service_add(char* username, char* groupname, char* sendbuf, int* bufLen);
int group_service_chat(char* username,char* groupname, char* msg,int msglen, char* sendbuf, int* bufLen);

#endif
